let Flyweight = function () {
    let created = [];
    function create() {
        let dom = document.createElement('div');
        document.getElementById('container').appendChild(dom);
        created.push(dom);
        return dom;
    }
    return {
        getDiv() {
            if (created.length < 5) {
                return create();
            } else {
                let div = created.shift();
                created.push(div);
                return div;
            }
        }
    }
}();

let article = [];
for(let i = 0; i < 17; i++) {
    article.push(`这是第${i+1}条新闻`);
}

let paper = 0, num = 5, len = article.length;
for (let i = 0; i < 5; i++) {
    if (article[i])
        Flyweight.getDiv().innerHTML = article[i];
}
document.getElementById('next_page').onclick = function () {
    if (article.length < 5)
        return;
    let n = ++paper * num % len;
    for (let j = 0; j < 5; j++) {
        if (article[n + j]) {
            Flyweight.getDiv().innerHTML = article[n + j];
        } else if(article[n + j - len]) {
            Flyweight.getDiv().innerHTML = article[n + j - len];
        } else{
            Flyweight.getDiv().innerHTML = '';
        }
    }
};